<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('租赁管理基本信息列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
    <div class="ui-layout-west">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa fa-sitemap"></i> 组织机构
                </div>
                <div class="box-tools pull-right">
                    <a type="button" class="btn btn-box-tool" href="javascript:void(0)" onclick="dept()" title="管理部门"><i class="fa fa-edit"></i></a>
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新部门"><i class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
         <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <input type="hidden" id="deptId" value="205" name="deptId">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>合同编号：</label>
                                    <input type="text" name="contractNo"/>
                                </li>
                                <li>
                                    <label>签订时间：</label>
                                    <input type="text" class="time-input" placeholder="请选择签订合同时间" name="startTime"/>
                                </li>
                                <li>
                                    <label>到期时间：</label>
                                    <input type="text" class="time-input" placeholder="请选择合同到期时间" name="endTime"/>
                                </li>
                                <li>
                                    <label>承租人：</label>
                                    <input type="text" name="name"/>
                                </li>
                                <li>
                                    <label>联系人：</label>
                                    <input type="text" name="contacts"/>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="add()" shiro:hasPermission="system:manage:add">
                        <i class="fa fa-plus"></i> 添加
                    </a>
<!--                    <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:manage:edit">-->
<!--                        <i class="fa fa-edit"></i> 修改-->
<!--                    </a>-->
                    <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:manage:remove">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                    <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:manage:export">
                        <i class="fa fa-download"></i> 导出
                    </a>
                </div>
                <div class="col-sm-12 select-table table-bordered">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <th:block th:include="include :: bootstrap-table-resizable-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:manage:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:manage:remove')}]];
        var leaseDatas = [[${@dict.getType('lease_purpose')}]];
        var collectDatas = [[${@dict.getType('collect_method')}]];
        var key = [[${key}]];
        var prefix = ctx + "system/manage";


        $(function() {
            var panehHidden = false;
            if ($(this).width() < 769) {
                panehHidden = true;
            }
            $('body').layout({ initClosed: panehHidden, west__size: 185, resizeWithWindow: false });
            // 回到顶部绑定
            if ($.fn.toTop !== undefined) {
                var opt = {
                    win:$('.ui-layout-center'),
                    doc:$('.ui-layout-center')
                };
                $('#scroll-up').toTop(opt);
            }
            queryDeptTree();
            queryUserList();
        });

        function queryUserList() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "租赁管理基本信息",
                columns: [{
                    checkbox: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a type="button" class="btn btn-success btn-xs" href="javascript:void(0)" onclick="uploadSyncData(\'' + row.id + '\')"><i class="fa fa-file"></i>附件</a>');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    },
                    width: 200
                },
                {
                    field: 'id',
                    title: '主键ID',
                    visible: false
                },
                {
                    field: 'assetsId',
                    title: '房产资产ID',
                    visible: false
                },
                {
                    field: 'contractNo',
                    title: '合同编号'
                },
                {
                    field: 'startTime',
                    title: '签订合同时间'
                },
                {
                    field: 'endTime',
                    title: '合同到期时间',
                    visible: false
                },
                {
                    field: 'name',
                    title: '承租人名称',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value,5);
                    },
                },
                {
                    field: 'cardId',
                    title: '承租人证件号',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value,5);
                    },
                    visible: false
                },
                {
                    field: 'contacts',
                    title: '联系人'
                },
                {
                    field: 'contactPhone',
                    title: '联系电话',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value,5);
                    },
                    visible: false
                },
                {
                    field: 'address',
                    title: '入驻地点',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value,5);
                    },
                },
                {
                    field: 'leasePurpose',
                    title: '租赁用途',
                    visible: false
                },
                {
                    field: 'leaseType',
                    title: '租金类别',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(leaseDatas, value);
                    },
                    visible: false
                },
                {
                    field: 'charterMoney',
                    title: '租金价格(元/月)'
                },
                {
                    field: 'cashDeposit',
                    title: '保证金',
                    visible: false
                },
                {
                    field: 'acreage',
                    title: '租赁面积'
                },
                {
                    field: 'leaseArea',
                    title: '租赁区域'
                },
                {
                    field: 'increaseRate',
                    title: '递增率',
                    visible: false
                },
                {
                    field: 'increaseCycle',
                    title: '递增周期',
                    visible: false
                },
                {
                    field: 'reducelPrice',
                    title: '减免租金',
                    visible: false
                },
                {
                    field: 'collectMethod',
                    title: '租金收取方式',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(collectDatas, value);
                    }
                },
                {
                    field: 'contractPeople',
                    title: '合同经办人',
                    visible: false
                },
                {
                    field: 'discounts',
                    title: '优惠政策',
                    visible: false
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'createUserId',
                    title: '创建者ID',
                    visible: false
                },
                {
                    field: 'updateUserId',
                    title: '最后更新者ID',
                    visible: false
                }
                ]
            };
            $.table.init(options);
        };

        function queryDeptTree()
        {
            var url = ctx + "system/common/deptTreeData/"+key;
            var options = {
                url: url,
                expandLevel: 2,
                onClick : zOnClick
            };
            $.tree.init(options);

            function zOnClick(event, treeId, treeNode) {
                var deptId = treeNode.id
                $("#deptId").val(deptId);
                $.table.search();
            }
        }

        $('#btnExpand').click(function() {
            $._tree.expandAll(true);
            $(this).hide();
            $('#btnCollapse').show();
        });

        $('#btnCollapse').click(function() {
            $._tree.expandAll(false);
            $(this).hide();
            $('#btnExpand').show();
        });

        $('#btnRefresh').click(function() {
            queryDeptTree();
        });

        /* 自定义重置-表单重置/隐藏框/树节点选择色/搜索 */
        function resetPre() {
            resetDate();
            $("#formId")[0].reset();
            $("#deptId").val("");
            $(".curSelectedNode").removeClass("curSelectedNode");
            $.table.search();
        }

        function dept() {
            var url = ctx + "system/assets";
            $.modal.openTab("资产管理", url);
        }

        function uploadSyncData(id){
            $.modal.open("附件上传", ctx+"system/common/uploads/"+id);
        }

        function add(){
            var deptId = $("#deptId").val();
            $.modal.open("新增租赁合同", prefix+"/addbyDeptId/"+deptId);
        }

        function edit(id){
            var deptId = $("#deptId").val();
            $.modal.open("修改租赁合同", prefix+"/editbyDeptId/"+id+"/"+deptId);
        }
    </script>
</body>
</html>